<?php

namespace App\Http\Controllers\Home\Pl;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class GoodsPlController extends Controller
{
    //商品评论展示
    public function index($id)
    {
    	//取出此订单的信息
    	$goods_id = DB::table('orders') -> where('id',$id) -> first() -> goods_id;
    	$uid = DB::table('orders') -> where('id',$id) -> first() -> member_id;
    	//取出购买时间
    	$addtime = DB::table('orders') -> where('id',$id) -> first() -> addtime;
    	//取出商品的信息
    	$goods = DB::table('goods') -> where('id',$goods_id) -> first();
    	//取出用户信息
    	$user = DB::table('users') -> where('id',$uid) -> first(); 
    	return view('home.goodspl.goodspl',['addtime' => $addtime,'goods' => $goods,'user' => $user,'id' => $id]);
    }

    public function pl(Request $request,$id)
    {

    	$data = $request -> except('_token');
    	$time = time();
    	$data['addtime'] = $time;
    	//查询出该商品的系列值 发布成功跳到该商品详情页面
    	$series = DB::table('goods') -> where('id',$request -> goods_id) -> first() -> series;
    	$res = DB::table('comment') -> insert($data);
    	if($res)
    	{
    		//修改订单状态
    		DB::table('orders') -> where('id',$id) -> update(['post_status' => 7]);
    		//跳到商品详情
    		return redirect('home/goods/index' . '/' . $request -> goods_id . '/' . $series);
    	}
    }
}
